<?php
class Admin_about extends Contact_Controller{
	function __construct(){
		parent :: __construct();
		$this->load->model('About_m');
		$this->_data['sidebar']="about";
		
		
	}
	
	function index(){
		$this->about_information();	
	}
	
	//--view about information--//
	function about_information(){
		is_admin();
		$this->_data['page_title'] = "About us information";
		//add new about content if about content is null
		$query_about_content = $this->About_m->check_exist_record(); 
		if($query_about_content){ //if exist content on about, load form edit
			$contentRow = $query_about_content->row();
			$this->edit_about_information($contentRow->id);
		}else{//if not exist content on about, load form add
			$this->add_about_information();	
			
		}   
		
		
	}
	
	function add_about_information(){
			$config = array(
							array("field" => "content", 
								  "label" => lang("content"),
								  "rules" => "required|xss_clean|trim"
								 )
							
				       		);
			$this->form_validation->set_rules($config);
			
			if($this->input->post("add_about_content")){
				if($this->form_validation->run()=== false){
					$this->display_admin('admin/about/add_about_information');	
				}else{
					$data = array("id"=>1, "content"=>$this->input->post("content"));
					if($this->About_m->add_about_content($data)){
						$this->session->set_flashdata('error', lang('add') ." ". lang('success'));
						redirect('admin_about');
					}	
				}		
			}else{
				$this->display_admin('admin/about/add_about_information');		
			}
	}
	
	function edit_about_information($id =  null){
			
			$config = array(
							array("field" => "content", 
								  "label" => lang("content"),
								  "rules" => "required|xss_clean|trim"
								 )
							
				       		);
			$this->form_validation->set_rules($config);
			$query_about_content = $this->About_m->load_about_content($id);
			if($query_about_content === FALSE){
				redirect("Admin_about");
			}
			$this->_data['about_content'] = $query_about_content->row();
			if($this->input->post("edit_about_content")){
				if($this->form_validation->run()=== false){
					$this->display_admin('admin/about/update_about_information');	
				}else{
					$data = array("content" => $this->input->post("content"));
					if($this->About_m->edit_about_content($id, $data)){
						$this->session->set_flashdata('error', lang('edit_profile') ." ". lang('success'));
						redirect('admin_about');
					}	
				}		
			}else{
				$this->display_admin('admin/about/update_about_information');		
			}
		
	}
	

}

	